package com.zziq.mianshi.exception;

import com.zziq.mianshi.common.ErrorCode;

/**
 * 抛异常工具类
 */
public class ThrowUtils {

    /** @Title: throwIf
     * @Author: Mr·zziq
     * @Date: 2024-12-04 19:02:24
     * @Params: [condition, runtimeException] 
     * @Return: void
     * @Description: 条件成立则抛异常
     */
    public static void throwIf(boolean condition, RuntimeException runtimeException) {
        if (condition) {
            throw runtimeException;
        }
    }

    /** @Title: throwIf
     * @Author: Mr·zziq
     * @Date: 2024-12-04 19:02:29
     * @Params: [condition, errorCode] 
     * @Return: void
     * @Description: 条件成立则抛异常
     */
    public static void throwIf(boolean condition, ErrorCode errorCode) {
        throwIf(condition, new BusinessException(errorCode));
    }

    /** @Title: throwIf
     * @Author: Mr·zziq
     * @Date: 2024-12-04 19:02:34
     * @Params: [condition, errorCode, message] 
     * @Return: void
     * @Description: 条件成立则抛异常
     */
    public static void throwIf(boolean condition, ErrorCode errorCode, String message) {
        throwIf(condition, new BusinessException(errorCode, message));
    }
}
